package com.woniuxy.yygh.user.controller;

import com.woniuxy.yygh.common.result.Result;
import com.woniuxy.yygh.common.utils.AuthContextHolder;
import com.woniuxy.yygh.model.user.Patient;
import com.woniuxy.yygh.user.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: patient 病人controller
 * <P> Date: 2022/3/4:22:45
 * <P> Description:
 */
@RestController
@RequestMapping("/admin/user/patient")
public class PatientController {

    @Autowired
    private PatientService patientService;



    /**
        * TODO:添加就诊人列表
    **/
    @PostMapping("/auth/savePatient")
    public Result savePatient(@RequestBody Patient patient,
                              HttpServletRequest request){
        //获得当前用户的登录信息
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.save(patient);
        return Result.ok();
    }

    /**
     * TODO: 根据id获取就诊人信息
     **/
    @GetMapping("/auth/getPatient/{id}")
    public Result getPatient(@PathVariable Long id){
        Patient patient = patientService.getPatientById(id);
        return  Result.ok(patient);
    }


    /**
     * TODO:修改就诊人信息
     **/
    @PutMapping("/auth/updatePatient")
    public Result updatePatient(@RequestBody Patient patient){
        patientService.updateById(patient);
        return Result.ok();
    }


    /**
     * TODO:根据就诊人id 删除就诊人信息
     **/
    @DeleteMapping("/auth/removePatient/{id}")
    public Result updatePatient(@PathVariable Long id){
        patientService.removeById(id);
        return Result.ok();
    }


    /**
        * TODO:根据就诊人的id获取就诊人的信息
    **/
    @GetMapping("/inner/get/{id}")
    public Patient getPatientOrder(@PathVariable Long id){
        Patient patient = patientService.getPatientById(id);
        System.out.println("封装后" + patient);
        return patient;
    }



}
